package com.xbfinal.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xbfinal.commonUtils.Result;
import com.xbfinal.eduservice.entity.EduCourse;
import com.xbfinal.eduservice.entity.EduTeacher;
import com.xbfinal.eduservice.service.EduCourseService;
import com.xbfinal.eduservice.service.EduTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Title: IndexFrontController
 * @Author 笑霸fianl
 * @Package com.xbfinal.eduservice.controller.front
 * @Date 2023/2/27 17:47
 * @描述:
 */
@RestController
@Slf4j
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {


    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;


    @GetMapping("index")
    public Result index(){

        //查询前八个热门课程
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id");
        courseQueryWrapper.last("limit 8 ");
        List<EduCourse> eduList = eduCourseService.list(courseQueryWrapper);

        //查询前4个名师
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id");
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(teacherQueryWrapper);


        log.info("eduList长度"+eduList.size()+"\n");
        log.info("teacherList长度"+teacherList.size()+"\n");

        return Result.ok().add("eduList",eduList)
                .add("teacherList",teacherList);
    }
}
